<?php

require_once dirname(__FILE__).'/../lib/paymentGeneratorConfiguration.class.php';
require_once dirname(__FILE__).'/../lib/paymentGeneratorHelper.class.php';

/**
 * payment actions.
 *
 * @package    sf_sandbox
 * @subpackage payment
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 12474 2008-10-31 10:41:27Z fabien $
 */
class paymentActions extends autoPaymentActions
{

      protected function buildCriteria()
  {
    if (is_null($this->filters))
    {
      $this->filters = $this->configuration->getFilterForm($this->getFilters());
    }

    $criteria = $this->filters->buildCriteria($this->getFilters());

    $this->addSortCriteria($criteria);

    $event = $this->dispatcher->filter(new sfEvent($this, 'admin.build_criteria'), $criteria);
    $criteria = $event->getReturnValue();

      if($this->getUser()->hasCredential('partner') and !$this->getUser()->isSuperadmin() )
    {
        $crit1=$criteria->getNewCriterion(sfGuardUserPeer::PARTNER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        $crit2=$criteria->getNewCriterion(PaymentPeer::USER_ID,$this->getUser()->getAttribute( 'user_id', null, 'sfGuardSecurityUser' ));
        $crit1->addOr($crit2);
        $criteria->add($crit1);
        $criteria->addJoin(sfGuardUserPeer::ID,PaymentPeer::USER_ID);
    }

    return $criteria;
  }


  public function executeIndex(sfWebRequest $request)
  {

     parent::executeIndex($request);

            $c = $this->buildCriteria();
            $c->addSelectColumn('SUM(payment.summa)');
            $cnt = PaymentPeer::doCount($c);
            if($cnt==0)  $this->sum = 0;
            $items = PaymentPeer::doSelectStmt($c);

             while($i = $items->fetch())
             {
                  $this->sum = ($i[0]/100)*sfConfig::get('app_comission');
             }

  }


}
